package yh.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author yh
 */
public class RandomUtil {

    public static  char randoms[] = {'0', '1', '2', '3', '4', '5','6', '7', '8', '9','a', 'b', 'c', 'd', 'e', 'f','g', 'i', 'j', 'k', 'l', 'm','n', 'o', 'o', 'q', 'r', 's',
            't', 'u', 'v', 'w', 'x', 'y','z','A', 'B', 'C', 'D', 'E', 'F','G', 'I', 'J', 'K', 'L', 'M','N', 'O', 'O', 'Q', 'R', 'S',
            'T', 'U', 'V', 'W', 'X', 'Y','Z'};
    /**
     * 获取验证码(随机5位)
     * @return
     */
    public static String getCode(){
        String code = "";

        Random sc = new Random();
        for(int i =0;i<5;i++){
            int sub = sc.nextInt(randoms.length);
            code += randoms[sub] + "";
        }
        return  code;
    }

    /**
     *随机字符串
     */
    public static String getRandomUrl(){
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYYMMDDHHMMSS);
        String str = sdf.format(new Date());
        Random sc = new Random();
        for(int i=0;i<4;i++){
            int sub = sc.nextInt(randoms.length);
            str += randoms[sub] + "";
        }
        return str;
    }
}
